const app = getApp<IAppOption>();

Page<{ userInfo?: WechatMiniprogram.UserInfo }, Record<string, any>>({
  data: {
    userInfo: undefined
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo
      });
    }
  },
  toAboutUs() {
    wx.navigateTo({
      url: '/pages/about-us/about-us'
    });
  },
  toVisitorManage() {
    wx.navigateTo({
      url: '/pages/visitor-list/visitor-list'
    });
  },
  toAddressManage() {
    wx.navigateTo({
      url: '/pages/address-list/address-list'
    });
  },
  toFeedback() {
    wx.navigateTo({
      url: '/pages/feedback/feedback',
      fail: () => {},
      complete: () => {}
    });
  },
  getUserInfo() {
    if (!this.data.userInfo) {
      wx.getUserProfile({
        desc: '获取用户信息',
        success: (res) => {
          const userInfo = res.userInfo;
          app.globalData.userInfo = userInfo;
          this.setData({
            userInfo: userInfo
          });
        },
        fail: (err) => {
          wx.showModal({
            icon: 'error',
            title: '获取失败',
            content: err.errMsg
          });
        }
      });
    }
  }
});

export {};
